package com.tengju.bff.interfaces.covercharge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tengju.bff.interfaces.covercharge.entity.po.CustPaidTrans;
import com.tengju.bff.interfaces.covercharge.mapper.CustPaidTransMapper;
import com.tengju.bff.interfaces.covercharge.service.ICustPaidTransService;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 转账申请记录表 服务实现类
 * </p>
 *
 * @author qumengmeng
 * @since 2020-09-23
 */
@Service
public class CustPaidTransServiceImpl extends ServiceImpl<CustPaidTransMapper, CustPaidTrans> implements ICustPaidTransService {

    @Override
    public Integer countByReqSn(String reqSn) {
        QueryWrapper<CustPaidTrans> wrapper = new QueryWrapper<CustPaidTrans>();
        wrapper.eq("req_sn",reqSn);

        return baseMapper.selectCount(wrapper);
    }

    @Override
    public boolean updateByReqSn(String reqSn, CustPaidTrans custPaidTransEntry) {
        custPaidTransEntry.setUpdateTime(LocalDateTime.now());
        CustPaidTrans custPaidTransWhere = new CustPaidTrans();
        custPaidTransWhere.setReqSn(reqSn);
        return this.update(custPaidTransEntry, new UpdateWrapper<>(custPaidTransWhere));
    }

    @Override
    public List<CustPaidTrans> getCheckList() {
        String maxUpdateAt = "";
        Integer maxQueryTry = 10;
        String startTime = "2020-08-14";
        return baseMapper.getCheckList(maxUpdateAt, maxQueryTry, startTime);
    }

    @Override
    public CustPaidTrans getReqData(String reqSn) {
        QueryWrapper<CustPaidTrans> wrapper = new QueryWrapper<CustPaidTrans>();
        wrapper.eq("req_sn",reqSn);

        return baseMapper.selectOne(wrapper);
    }

    @Override
    public String getAddJsonString(String s, Object jsonTransferResponse) {
        JSONArray jsonArray= JSONArray.fromObject(s);
        jsonArray.add(jsonTransferResponse);

        return jsonArray.toString();
    }
}
